Skip to main content

Placing a Project in Git Management

Repositories and branches in CODESYS Git

To manage a CODESYS project in Git with the help of CODESYS Git, it is first of all sufficient to use a purely local Git repository in the "project storage" (working directory), also referred to as a "Git repository" in the following text. For the collaboration with other developers on the project, the local Git repository can be linked with a "remote repository" which is accessible to everyone.

Work on the project managed in Git is done first in local branches (work statuses). The local branches can track a remote branch (link to the remote repository). Remote branches are the existing representatives in the local Git repository of the respective branch in the remote repository.

Tip

You can use the Move Repository command to move a Git repository to another location in the file system.

Tip

You can use the Disconnect from Git Repository command to unlink a project from the source code management in Git.

Warning

When encryption is set for the CODESYS project (CODESYS-Project SettingsSecurity), the Git repository (neither local nor remote) is not automatically protected accordingly.

Using git init to place a CODESYS project in Git management

Requirement: CODESYS Git is installed. A CODESYS project is open.

  1. Prepare an empty directory in the file system for the Git project repository to contain the local Git repository. Example: D:\git_local\rep1

  2. In CODESYS Git, open the CODESYS project which should be placed under Git management. Example: myproj.project.

  3. Click the Git → Initialize Git Repository command.

    The Initialize Git Repository dialog opens.

  4. In the dialog, specify the path of the empty directory for the Git project storage (example: D:\git_local\rep1). The Git repository created there is your local "master".

    1. If there is no global configuration file .gitconfig in the local user directory (example: C:\Users\m.muster), then a dialog prompt will open for you to create a basic configuration for all CODESYS Git actions. You get the same dialog for entering some parameters as via the Git Config command. The default setting for Default Branch is master. Enter your user data Username and Email address (example m.muster, m.muster@company.com).

    2. The objects in the project navigator are provided with blue plus signs _git_icon_status_added.png (status: "added"), and the root node (project name) is provided with an orange square _git_icon_status_modified.png (status: "changed").

    3. The path of the Git project storage is displayed in the Git → Project Settings view.

    4. As a result, the project management in the Git repository located in the project storage is initialized.

  5. Save the project (as usual without Git management) in a separate project directory (example: D:\git_projects\myproj.project). Note: The project files are therefore subject to double data management.

  6. Open the Git Status view. In Unstaged Changes in the lower part, select the displayed project objects. Then click the _git_icon_add.png button to stage it for a commit.

    The objects are moved above to Staged Changes.

  7. Click the _git_icon_commit.png button (commit). In the Commit staged changes dialog, enter a commit message and click OK to confirm.

    The current status of the project objects is committed to the local repository.

  8. Click the Git → Git History command.

    1. In the History view, the first commit for the "master" is shown with more information.

    2. In the project navigator, solid green circle symbols _git_icon_status_normal.png are displayed in front of the committed objects and in front of the root. This means that the status of the project is in sync with its status in the Git repository.

  9. Click the Git → Git Branches command and enable the Local (1) filter.

    The default branch for the Git repository is visible as master (refs/heads/master).

  10. In the file system, go to the local repository D:\git_local\rep1.

    Now the directory .git (the actual Git repository) is located here with the subdirectory project and the files .gitattributes, .gitignore, and .apsession. The directory project contains the objects of the CODESYS project.

  11. Now you can still link the project (when necessary) with a remote repository.

Using Clone Git Repository to create a new CODESYS project already in Git management

With Git Clone, a new CODESYS project is created, which is version-managed in Git. As a result, cloning a remote repository creates the new project storage (the new working directory with the Git repository).

Requirement: CODESYS Git is installed. You have access to a remote repository.

  1. Open CODESYS Git. Click the Git → Clone Git Repository command. It is available when no CODESYS project is open.

    The Git Clone dialog opens.

  2. In Source URL, specify the URL or file path of the remote repository to be cloned (example: D:\git_remotes\remote1).

    In Git storage path, specify the empty file directory intended for the new Git project storage (new Git repository) (example: D:\git_local\rep1).

    In Project file, specify a project directory where the new CODESYS project should be saved in addition to and outside of Git (!) (example: D:\git_projects\myproj1.project, double data management!).

    In Project file type, select whether it should be a standard project or a library project. Confirm the dialog.

    If there is no global configuration file .gitconfig in the local user directory (example: C:\Users\m.muster), then a dialog prompt will open for you to create a basic configuration for all CODESYS Git actions. See the instructions above for initializing a Git project (Step 4).

    If the Git option Accept self signed certificate is not selected, then CODESYS Git first checks the certificate for the connection to the server from which the project should be cloned. If the certificate is not trusted, then you will be given the option of allowing the connection after a personal check.

    The new project is opened. The new working directory is created and automatically initialized as the Git repository. It first has the exact status of the remote repository when the cloning occurred.

  3. In the CODESYS project, click the Git → Git Branches command.

    In the Git Branches view, the remote branches are already visible. By default, for the remote "master" branch, a local "master" branch is also created, which tracks the remote branch. Now you can start working in this local branch immediately. In addition, a link (tracking) of the local branch to the "representative" remote branch (origin/master) of the new Git repository is already established.

Linking a project to a remote repository

Requirement: A project is managed in Git in CODESYS Git. Now you want to establish a link to a remote repository to synchronize there your commits with the commits of others.

  1. Click the Git → Git Remotes command. In the Git Remotes view, click the _git_icon_add_remote.pngAdd button.

    The Add new Git Remote dialog opens.

  2. Specify the path and a name for the remote repository to be linked. Example: Alias Name: origin, URL: D:\git_remote.

  3. Run the _git_icon_fetch.png Fetch command and then click the Git → Git Branches command to switch to the Git Branches view.

    Credentials are usually required to access a remote repository. Only if no valid credentials are found on the computer will the Credentials needed dialog for your input. For more information, see: Credentials needed.

  4. Select the Remote (<n>) filter.

    You see the remote branches.

  5. Unselect the Remote (<n>) filter. Select the Local (1) filter. Select the master entry and click Upstream Set. If there is still no remote branch (origin/master) for the selected remote repository, then the following happens:

    The Set Upstream Remote for Branch dialog opens. The remote name origin is already predefined.

  6. Click OK to confirm the entries.

    → The Tracking and Current options are selected for the master. In Tracked Branch, Name, origin/master is displayed.

    This means that the remote branch origin/master for the remote repository is created internally. This is only used as a representative: No work is done directly on this branch.

  7. Select the master and click Push. Select the Remote (1) filter.

    Now the representative branch origin/master under Git Branches Remote (1) is also displayed. The link from the local master to the remote repository is established by means of its representative origin/master.

  8. In the Git Branches Local (<1>) view, you can now use the Track branch command to link the local branch (master) of the Git repository to the new remote branch of the remote repository.